{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[1m\u001b[32mave. squared distance = 51.376919095994744\u001b[0m\n",
      "\u001b[1mvtkTransform is available with getTransform():\u001b[0m\u001b[7m\u001b[1m[(vtkCommonTransformsPython.vtkLandmarkTransform)0x7f14aac4e828]\u001b[0m\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4c48fdf769854e8494a5b04afbd30dfe",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, camera=[4.5, 4.5, 4.5, 0.0, 0.0, 0.0, 1.0, …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\"\"\"\n",
    "Align 2 shapes and for each vertex of the first draw\n",
    "and arrow to the closest point of the second.\n",
    "The source transformation is accessible with getTransform()\n",
    "rigid=True doesn't allow scaling\n",
    "\"\"\"\n",
    "from vtkplotter import *\n",
    "#embedWindow(False)# then press Esc to close the external window\n",
    "\n",
    "vp = Plotter()\n",
    "\n",
    "limb = vp.load(datadir + \"270.vtk\")\n",
    "rim  = vp.load(datadir + \"270_rim.vtk\").c(\"r\").lw(4)\n",
    "vp.show()\n",
    "\n",
    "arim = alignICP(rim, limb, rigid=True).c(\"g\").lw(5)\n",
    "vp += arim\n",
    "\n",
    "d = 0\n",
    "for p in arim.coordinates():\n",
    "    cpt = limb.closestPoint(p)\n",
    "    d += mag2(p - cpt)  # square of residual distance\n",
    "\n",
    "printc(\"ave. squared distance =\", d / arim.N(), c=\"g\")\n",
    "printc(\"vtkTransform is available with getTransform(): \", end=\"\")\n",
    "printc([arim.getTransform()], invert=True)\n",
    "vp.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "closePlotter()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
